package com.ruoyi.system.domain;

import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.format.NumberFormat;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.core.domain.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * 直接费用对象 direct
 * 
 * @author xuliang
 * @date 2024-03-29
 */
@EqualsAndHashCode(callSuper = true)
@Data
@ToString
public class NoContract extends BaseEntity
{

    private static final long serialVersionUID = 1L;

    @ExcelIgnore
    private Long id;

    @ExcelProperty(value = "序号")
    @ColumnWidth(8)
    private Long no;

    /** 直接费用名 */
    @ExcelProperty(value = "无合同费用名称")
    @ColumnWidth(15)
    private String noContractName;

    /** 项目编号 */
    @ExcelProperty(value = "项目编号")
    @ColumnWidth(15)
    private String projectCode;

    @ExcelIgnore
    private String projectName;

    /** 累计已发生成本（含税） */
    @ExcelProperty(value = "累计已发生成本（含税）")
    @ColumnWidth(20)
    private BigDecimal realTotalWithTax;

    /** 实际进项税率 */
    @ExcelProperty(value = "实际进项税率")
    @ColumnWidth(10)
    @NumberFormat(value = "0.00%")
    private Double taxRate;

    /** 已发生成本理论进项税额 */
    @ExcelProperty(value = "已发生成本理论进项税额")
    @ColumnWidth(20)
    private BigDecimal tax;

    /** 预计总成本理论进项税额 */
    @ExcelProperty(value = "预计总成本理论进项税额")
    @ColumnWidth(20)
    private BigDecimal expectTax;

    /** 供应商 */
    @ExcelProperty(value = "供应商")
    @ColumnWidth(15)
    private String supplier;

    /** 备注 */
    @ExcelProperty(value = "备注")
    @ColumnWidth(20)
    private String remark;


    /** 施工借方发生额合计（不含税） */
    @ExcelIgnore
    private BigDecimal totalNoTax;

    // 设置 realTotalWithTax 属性值的 setter 方法
    public void setRealTotalWithTax(BigDecimal realTotalWithTax) {
        this.realTotalWithTax = realTotalWithTax;
        calculateTax(); // 在设置属性值后调用计算方法
    }

    // 设置 taxRate 属性值的 setter 方法
    public void setTaxRate(Double taxRate) {
        this.taxRate = taxRate;
        calculateTax(); // 在设置属性值后调用计算方法
    }

    // 计算
    public void calculateTax() {
        if ((realTotalWithTax != null && BigDecimal.ZERO.compareTo(realTotalWithTax) != 0) && taxRate != null) {
            BigDecimal divisor = BigDecimal.ONE.add(BigDecimal.valueOf(taxRate));
            tax = realTotalWithTax.divide(divisor, 4, RoundingMode.HALF_UP)
                    .multiply(BigDecimal.valueOf(taxRate));
        } else {
            tax = BigDecimal.ZERO;
        }
    }

}
